var read_line = require('readline-sync')
read_line.setDefaultOptions({ prompt: '' })
var read_line = read_line.prompt
let [n, k] = read_line().split(' ').map((item) => parseInt(item)) // 读出n和k
let array = read_line().split('') // 得出字符串数组
let res = []
let count = 0
for (let i = 0; i < n; i++) { // 遍历这个字符串的长度
  let size = res.length
  for (let j = 0; j < size; j++) {
    let str = (res[j] + array[i]) // 计算拼接的字符串
    if (Number(str) < k) {
      res.push(str)
      continue
    }
    if (str % k === 0) { // 字符串拼接的能够整除k
      count = count + 1
    }
    res.push(str)
  }
  if (array[i] % k === 0) {
    count++
  }
  res.push(array[i]) // 把当前的放进去
}
console.log(count % 1000000007);